package com.xxx.video.login.activitys;

import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.Nullable;


import com.xxx.video.R;
import com.xxx.video.commen.activitys.BaseActivity;
import com.xxx.video.commen.utils.FontCacheUtils;
import com.xxx.video.commen.utils.ListUtils;
import com.xxx.video.commen.utils.StatusBarUtil;
import com.xxx.video.commen.views.FontTextView;
import com.xxx.video.login.beans.UserSecretGuardBean;
import com.xxx.video.login.presenters.ForgetPwdFirstPresenter;
import com.xxx.video.login.presenters.IForgetPwdFirstView;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class ForgetPwdFirstActivity extends BaseActivity<ForgetPwdFirstPresenter> implements IForgetPwdFirstView {
    public static final int START_FORGET_PWD_SECOND_ACTIVITY = 201;
    @BindView(R.id.tv_forget_pwd_first_security_question)
    TextView tvForgetPwdFirstSecurityQuestion;
    @BindView(R.id.tv_forget_pwd_first_first_question)
    TextView tvForgetPwdFirstFirstQuestion;
    @BindView(R.id.et_forget_pwd_first_first_question)
    EditText etForgetPwdFirstFirstQuestion;
    @BindView(R.id.tv_forget_pwd_first_second_question)
    TextView tvForgetPwdFirstSecondQuestion;
    @BindView(R.id.et_forget_pwd_first_second_question)
    EditText etForgetPwdFirstSecondQuestion;
    @BindView(R.id.tv_forget_pwd_first_third_question)
    TextView tvForgetPwdFirstThirdQuestion;
    @BindView(R.id.et_forget_pwd_first_third_question)
    EditText etForgetPwdFirstThirdQuestion;
    @BindView(R.id.tv_forget_pwd_first_next)
    TextView tvForgetPwdFirstNext;
    /**
     * user name
     */
    private String mUserName;
    /**
     * user set secret guard
     */
    private List<UserSecretGuardBean.ListBean> mUserSecretGuardBeanList;

    @Override
    public void initToolbarData() {
        super.initToolbarData();
        showActionBar();
        StatusBarUtil.getInstance().setStatusBarTransparent(this, true);
        setActionBarTitle(R.string.title_forget_first_activity);
        setIsShowActionbarLine(true);
        Typeface customFont = FontCacheUtils.getInstance().getTypeface(FontTextView.ttf3, this);
        etForgetPwdFirstFirstQuestion.setTypeface(customFont);
        etForgetPwdFirstSecondQuestion.setTypeface(customFont);
        etForgetPwdFirstThirdQuestion.setTypeface(customFont);
    }

    @Override
    protected ForgetPwdFirstPresenter createPresenter() {
        return new ForgetPwdFirstPresenter(this, this);
    }

    @Override
    public int getContentLayout() {
        return R.layout.activity_forget_pwd_first;
    }

    @Override
    public void initData(Bundle extras) {
        if (extras != null) {
            mUserName = extras.getString("userName");
        }
        getPresenter().getSecretGuard(mUserName);
    }

    @OnClick({R.id.tv_forget_pwd_first_next})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_forget_pwd_first_next:
                getPresenter().startForgetPwdSecondActivity();
                break;
            default:
                break;
        }
    }

    @Override
    public void startForgetPwdSecondActivity() {
        Bundle bundle = new Bundle();
        bundle.putString("userName", mUserName);
        intent2Activity(ForgetPwdSecondActivity.class, bundle, START_FORGET_PWD_SECOND_ACTIVITY);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            if (requestCode == START_FORGET_PWD_SECOND_ACTIVITY) {
                finish();
            }
        }
    }

    @Override
    public void initSecretGuardData2View(UserSecretGuardBean successOb) {
        if (ListUtils.isEmpty(successOb.list)) {
            showRootLayoutStatus(2);
            return;
        }
        mUserSecretGuardBeanList = successOb.list;
        for (int i = 0; i < successOb.list.size(); i++) {
            UserSecretGuardBean.ListBean listBean = successOb.list.get(i);
            if (i == 0) {
                tvForgetPwdFirstFirstQuestion.setText(listBean.fQuestionName);
            } else if (i == 1) {
                tvForgetPwdFirstSecondQuestion.setText(listBean.fQuestionName);
            } else if (i == 2) {
                tvForgetPwdFirstThirdQuestion.setText(listBean.fQuestionName);
            }
        }
        if (successOb.list.size() == 1) {
            tvForgetPwdFirstSecondQuestion.setVisibility(View.GONE);
            etForgetPwdFirstSecondQuestion.setVisibility(View.GONE);
            tvForgetPwdFirstThirdQuestion.setVisibility(View.GONE);
            etForgetPwdFirstThirdQuestion.setVisibility(View.GONE);
        } else if (successOb.list.size() == 2) {
            tvForgetPwdFirstThirdQuestion.setVisibility(View.GONE);
            etForgetPwdFirstThirdQuestion.setVisibility(View.GONE);
        }
    }

    @Override
    public String getFirstQuestion() {
        return etForgetPwdFirstFirstQuestion.getText().toString().trim();
    }

    @Override
    public String getSecondQuestion() {
        return etForgetPwdFirstSecondQuestion.getText().toString().trim();
    }

    @Override
    public String getThirdQuestion() {
        return etForgetPwdFirstThirdQuestion.getText().toString().trim();
    }

    @Override
    public List<UserSecretGuardBean.ListBean> getUserSecretGuardList() {
        return mUserSecretGuardBeanList;
    }

    @Override
    public void showRootLayoutStatus(int status) {
        showLayoutStatus(status);
    }
}
